package day17;

public class Order {
    public static void main(String[] args) {
        Order od=new Order();
        new Thread(new T1()).start();
        new Thread(new T2()).start();
        new Thread(new T3()).start();
    }

static class T1 implements Runnable{
    public void run() {
        String name=Thread.currentThread().getName();
        for (int i=0;i<10;i++){
            synchronized (T1.class){
                System.out.println(name+"在运行！");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                T1.class.notify();
                try {
                    T1.class.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

static class T2 implements Runnable{
    public void run() {
        String name=Thread.currentThread().getName();
        for (int i=0;i<10;i++){
            synchronized (T2.class){
                System.out.println(name+"在运行！");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                T2.class.notify();
                try {
                    T2.class.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

static class T3 implements Runnable{
    public void run() {
        String name=Thread.currentThread().getName();
        for (int i=0;i<10;i++){
            synchronized (T3.class){
                System.out.println(name+"在运行！");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                T3.class.notify();
                try {
                    T3.class.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
}